//
//  YBMineUseRecordCell.swift
//  Moonlight
//
//  Created by Penlon Kim on 2023/7/1.
//  Copyright © 2023 Moonlight Game Streaming Project. All rights reserved.
//

import UIKit
import SnapKit

class YBMineUseRecordCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
        self.backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        let line = UIView(color: kRGBColor(191, 190, 190))
        
        contentView.addSubview(_contentView)
        _contentView.addSubviews([loginTimeLabel, logoutTimeLabel, line, durationLabel])
        
        _contentView.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.left.right.equalToSuperview().inset(10)
        }
        
        loginTimeLabel.snp.makeConstraints { make in
            make.top.equalTo(12)
            make.left.right.equalToSuperview().inset(20)
            make.height.equalTo(18)
        }
        
        logoutTimeLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(20)
            make.top.equalTo(loginTimeLabel.snp.bottom).offset(8)
            make.height.equalTo(18)
        }
        
        line.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(20)
            make.height.equalTo(0.3)
            make.top.equalTo(logoutTimeLabel.snp.bottom).offset(7)
        }
        
        durationLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(20)
            make.height.equalTo(18)
            make.top.equalTo(line.snp.bottom).offset(7)
            make.bottom.equalTo(-12)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - lazy
    private lazy var _contentView: UIView = {
        let view = UIView(color: .lightWhiteDark33)
        view.bk_addStyleWith(cornerRadius: 4, corners: .allCorners)
        return view
    }()
    
    /// 登录时间
    private lazy var loginTimeLabel = self.bk_addLabel(font: .systemFont(ofSize: 14), bgColor: .clear)
    /// 退出时间
    private lazy var logoutTimeLabel = self.bk_addLabel(font: .systemFont(ofSize: 14), bgColor: .clear)
    /// 总计时长
    private lazy var durationLabel = self.bk_addLabel(font: .systemFont(ofSize: 14), bgColor: .clear)
    
}

// MARK: - Public
extension YBMineUseRecordCell {
    
    func updateCell() {
        loginTimeLabel.attributedText = NSMutableAttributedString("登录时间：") { $0
            .foregroundColor(ColorDef.gray184)
        }.addText("2023-05-23 10: 13:29") { $0
            .foregroundColor(.lightBlack51DarkLight230)
        }
        
        logoutTimeLabel.attributedText = NSMutableAttributedString("退出时间：") { $0
            .foregroundColor(ColorDef.gray184)
        }.addText("2023-05-23 10: 13:29") { $0
            .foregroundColor(.lightBlack51DarkLight230)
        }
        
        durationLabel.attributedText = NSMutableAttributedString("总计时长：") { $0
            .foregroundColor(ColorDef.gray184)
        }.addText("2小时") { $0
            .foregroundColor(.lightBlack51DarkLight230)
        }
    }
    
}
